package com.code.apollo.pojo;

import com.code.apollo.utils.PropUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <Description>
 * 数据库
 * @author Jun Lee
 * @version 1.0
 * @createDate 2020/03/16 11:30
 * @see com.code.apollo.pojo
 */
@Data
@Builder
@NoArgsConstructor
public class DB {
    private static String mysqlUrl ;
    public static String driver;
    private static String defaultIp ;
    private static String defaultPort ;
    private String dbType;
    private String userName;
    private String passWord;
    private String url;

    static {
        mysqlUrl = PropUtil.customMap.get("mysqlUrl");
        driver = PropUtil.customMap.get("mysqlDriver");
        defaultIp = PropUtil.customMap.get("ip");
        defaultPort = PropUtil.customMap.get("port");
    }

    public DB(String dbType) {
        this(dbType,defaultIp,defaultPort,"");
    }

    public DB(String dbType,String db) {
        this(dbType,defaultIp,defaultPort,db);
    }

    public DB(String dbType,String ip,String port,String db) {
        this.dbType = dbType;
        if("MYSQL".endsWith(dbType.toUpperCase())) {
            this.url=mysqlUrl.replace("[ip]",ip).replace("[port]",port).replace("[db]",db);
        }
    }
}
